<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = true %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<%
   Dim strQry, strName, arrQry, arrValues, x
   Dim Recipient, FromVar, DefFrom, DefSubject, DefRedirect
   Dim Body, objMailer
   Dim FieldName, ErrTotal, V_err, A_err, CSZ_err, T_err, E_err
   
   strQry=Request.Form
   
   '<===============-------- Start of User Defined Variables --------================>
   
   Recipient = "vellacssr@earthlink.net"		'Where the message goes

   DefFrom = "volsub@redemptoristretreat.org"		'Used if no response email
   DefSubject = "Volunteer Submission"			'Used if form doesn't have an element named subject
   DefRedirect = "ThankYouVol.htm"			'Used if form doesn't have an element named redirect
  
   ' <===============-------- End of User Defined Variables --------================>
   
   if len(Request.Form("Email"))>4 then
      DefFrom = Request.Form("Email")
   end if
   
   if len(Request.Form("Subject"))>0 then
      DefSubject = Request.Form("Subject")
   end if
   
   if len(Request.Form("Redirect"))>0 then
      DefRedirect = Request.Form("Redirect")
   end if
   
   if not(ValidEmail(Recipient)) then
      Response.Write " for Recipient<BR>"
      Response.End
   end if
   
   if not(ValidEmail(DefFrom)) then
      Response.Write " for sender (" & DefFrom & ")<BR>"
      Response.End
   end if
   
   'If we made it this far everything looks OK, so its time to process the
   'Form Elements and send the email
   
   V_err = 0
   A_err = 0
   CSZ_err = 0
   T_err = 0
   E_err = 0
   ErrTotal = 0

   arrQry = split(strQry,"&")
   Body = string(40,"-") & chr(10) & chr(13)
   for x = lbound(arrQry) to ubound(arrQry)
      arrValues = split(arrQry(x),"=")
      Select Case arrValues(0)
        Case "Volname"
            If Len(arrValues(1)) < 3 Then
                ErrTotal = ErrTotal + 1
                V_err = 1
            End If
        Case "Address"
            If Len(arrValues(1)) < 5 Then
                ErrTotal = ErrTotal + 1
                A_err = 1
            End If
        Case "City_State_Zip"
            If Len(arrValues(1)) < 5 Then
                ErrTotal = ErrTotal + 1
                CSZ_err = 1
            End If
        Case "Telephone"
            If Len(arrValues(1)) < 12 Then
                ErrTotal = ErrTotal + 1
                T_err = 1
            End If
        Case "Email"
            If Len(arrValues(1)) < 5 Then
                ErrTotal = ErrTotal + 1
                E_err = 1
            End If
      End Select

      Body = Body & arrValues(0) & " = " & Request.Form(arrValues(0)) & chr(10) & chr(13)
   next

   Body = Body & chr(10) & chr(13) & chr(10) & chr(13) & "Form processing script v1.2"

   'OK, the form should contain data in the 5 above fields, or the client side script wouldn't have let it submit.
   'So even though we're here, we should have valid data, but let's check our error total and individual error flags to see what we've got.

    If ErrTotal > 0 Then
        'Well there was at least one error, display it/them in the browser
        Response.write "Errors detected in your Form Submission: " & ErrTotal & " <br>"
        If V_err = 1 Then
            Response.write "There was an error with your name, number of characters too short.<br>"
        End If

        If A_err = 1 Then
            Response.Write "There was an error with your Address, number of characters too short.<br>"
        End If

        If CSZ_err = 1 Then
            Response.write "There was an error with your City, State or Zip Code, number of characters too short.<br>"
        End If

        If T_err = 1 Then
            Response.write "There was an error with your telephone number, number of characters too short.<br>"
        End If

        If E_err = 1 Then
            Response.write "There was an error with your email address, number of characters too short.<br>"
        End If

        'Display a message in the browser and end the processing of this page, preventing the email from being sent.
        Response.write "<br><br>Please try filling out the form again. If it continues to be a problem, please contact the Retreat Center by phone."
        Response.End
    End If   
   
   'Response.Write Body
   'Set objMailer = CreateObject("CDONTS.Newmail")
   '   objMailer.From = DefFrom
   '   objMailer.To = Recipient
   '   objMailer.Subject = DefSubject
   '   objMailer.Body = Body
   '   objMailer.Send
   'Set objMailer = Nothing
   
	Set objMailer = CreateObject("CDO.Message")

	'This section provides the configuration information for the remote SMTP server.

	objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
	objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.appliedi.net"
	objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
	objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
	objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

	' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
	'objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
	'objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail@yourserver.com"
	'objMailer.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"

	objMailer.Configuration.Fields.Update

	'End remote SMTP server configuration section==

	objMailer.To = Recipient
	objMailer.Subject = DefSubject
	objMailer.From = DefFrom

	' we are sending a text email.. simply switch the comments around to send an html email instead
	'objMailer.HTMLBody = Body
	objMailer.TextBody = Body

	objMailer.Send

	Set objMailer = Nothing

   
   
   
   
      
   if DefRedirect = "" then
      Response.Write "<H1 align=center>Thank You for your offer of help</H1>"
      Response.Write "<HR>"
      Response.Write "You should be hearing from us if we need your help<BR>"
      Response.Write "<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;"
   else 
      Response.Redirect DefRedirect
   end if
   
%>

<%
   Function ValidEmail(Email)
      ValidEmail = true
      Dim Temp,Temp2
      if len(Email) > 100 then
         Response.Write "<br>Email address too long (" & Email & ")"
         ValidEmail = false
         Exit Function
      end if
      Email = LCase(Email)
      Temp = Split(Email,"@")
      if ubound(Temp) < 1 then
         Response.Write "<br>Email address not valid (" & Email & ")"
         ValidEmail = false
         Exit Function
      end if
      Temp2 = Split(Temp(1),".",-1,1)
      if ubound(Temp2) < 1 then
         Response.Write "<br>Email address not valid (" & Email & ")"
         ValidEmail = false
      end if
   End Function
%>

<BODY>
<P>&nbsp;</P>

</BODY>
</HTML>
